package com.oliver.picturebackendcommon.utils;

/**
 * @ClassName CommonUtils
 * @Description TODO
 * @Author snow
 * @Date 2025/1/12 18:40
 **/

import java.util.Random;

/**
 * 通用的工具类
 */
public class CommonUtils {

    // 生成随机字母和数字的组合
    private static String generateRandomAlphanumeric(int length) {
        String alphanumeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder(length);

        for (int i = 0; i < length; i++) {
            int index = random.nextInt(alphanumeric.length());
            sb.append(alphanumeric.charAt(index));
        }

        return sb.toString();
    }

    // 生成随机用户名称
    public static String generateRandomUsername(String nickname) {
        // 生成一个长度为6的随机字母数字组合
        String randomAlphanumeric = generateRandomAlphanumeric(6);
        return nickname + randomAlphanumeric;
    }

}
